package com.hjy.order.mq;

import com.hjy.order.entity.OrderEntity;
import com.hjy.order.entity.OrderReturnReasonEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@RabbitListener(queues = {"hello.java.queue1"})
public class TestMqService {

    @RabbitHandler
    public void test1(OrderReturnReasonEntity orderReturnReasonEntity, Message message, Channel channel) throws IOException {
        System.out.println("orderReturnReasonEntity = " + orderReturnReasonEntity);
        System.out.println("message = " + message);
        // 获取消息体, 也就是 orderReturnReasonEntity 的字节码
        byte[] body = message.getBody();
        // 获取参数
        MessageProperties messageProperties = message.getMessageProperties();
        System.out.println("channel = " + channel);
        long deliveryTag = messageProperties.getDeliveryTag();
        channel.basicAck(deliveryTag,false);
    }


    @RabbitHandler
    public void test2(OrderEntity orderEntity, Message message, Channel channel) throws IOException {
        System.out.println("OrderEntity = " + orderEntity);
        System.out.println("message = " + message);
        // 获取消息体, 也就是 orderReturnReasonEntity 的字节码
        byte[] body = message.getBody();
        // 获取参数
        MessageProperties messageProperties = message.getMessageProperties();
        System.out.println("channel = " + channel);
        long deliveryTag = messageProperties.getDeliveryTag();
        channel.basicAck(deliveryTag,false);
    }
}
